package com.xianyun.book.convertor;

import com.xianyun.book.domain.order.Order;
import com.xianyun.book.domain.order.OrderStatus;
import com.xianyun.book.gatewayimpl.database.dataobject.OrderDO;
import org.springframework.cglib.beans.BeanCopier;
import java.util.ArrayList;
import java.util.List;

import static java.util.stream.Collectors.toList;

/**
 * 订单转换器
 * @author ytt
 */
public class OrderConvertor {
    /**书籍转换复制器*/
    private static final BeanCopier ORDER_COPIER = BeanCopier.create(OrderDO.class, Order.class, false);

    public static List<Order> toDataTranslateList(List<OrderDO> resultDate){
        if (resultDate.size()>0){
            return resultDate.stream().map(orderDO -> {
                Order obj = new Order();
                ORDER_COPIER.copy(orderDO,obj,null);
                obj.setOrderStatus(OrderStatus.initOrderStatusById(orderDO.getOrderStatus()));
                return obj;
            }).collect(toList());
        }
        return new ArrayList<>();
    }
}
